#include "item.hpp"
#include "tile.hpp"
#include "ship.hpp"

void item::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
	states.texture = &(*quadTex);
	target.draw(quad, states);
}

item::item()
{
	quad.resize(4);
	quad[0].position = sf::Vector2f(0,0);
	quad[1].position = sf::Vector2f(tileSize * dim.x, 0);
	quad[2].position = sf::Vector2f(tileSize * dim.x, tileSize * dim.y);
	quad[3].position = sf::Vector2f(0,tileSize);
}

void item::damage(int HPoff)
{

}

void item::setTexID(int id)
{
	texID = id;
	quad[0].texCoords = sf::Vector2f(  texID    * tileSize * dim.x,  0);
	quad[1].texCoords = sf::Vector2f( (texID+1) * tileSize * dim.x,  0);
	quad[2].texCoords = sf::Vector2f( (texID+1) * tileSize * dim.x, (texID+1) * tileSize * dim.y);
	quad[3].texCoords = sf::Vector2f(  texID    * tileSize * dim.x, (texID+1) * tileSize * dim.y);
}

void item::setPos(sf::Vector2f inpos)
{
	pos = inpos;
	quad[0].position = sf::Vector2f(pos.x * tileSize * dim.x / 2, pos.y - tileSize * dim.y / 2);
	quad[1].position = sf::Vector2f(pos.x * tileSize * dim.x / 2, pos.y * tileSize * dim.y / 2);
	quad[2].position = sf::Vector2f(pos.x * tileSize * dim.x / 2, pos.y * tileSize * dim.y / 2);
	quad[3].position = sf::Vector2f(pos.x * tileSize * dim.x / 2, pos.y * tileSize * dim.y / 2);

}

tile * item::getTile()
{
    return( curShip.lock()->getTile(pos) );
}


